/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * QueryPlayerScoresViewImplJDialog.java
 *
 * Created on 19-feb-2010, 18:25:03
 */

package tpdisenio2009.mvp.display;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionListener;
import java.awt.event.ItemListener;
import java.util.List;
import java.util.Vector;
import javax.swing.DefaultComboBoxModel;
import javax.swing.table.DefaultTableModel;
import tpdisenio2009.model.beans.TournamentDate;

/**
 *
 * @author Pablito
 */
public class QueryPlayerScoresViewImpl extends javax.swing.JDialog implements QueryPlayerScoresView {

    /** Creates new form QueryPlayerScoresViewImplJDialog */
    public QueryPlayerScoresViewImpl(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        Dimension dim = this.getToolkit().getScreenSize();
        this.setLocation((dim.width - this.getWidth()) / 2,(dim.height - this.getHeight()) / 2);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jComboBoxFecha = new javax.swing.JComboBox();
        jLabelCotizacion = new javax.swing.JLabel();
        jLabelNombre = new javax.swing.JLabel();
        jLabelFecha = new javax.swing.JLabel();
        jLabelValorCotizacion = new javax.swing.JLabel();
        jButtonSalir = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jPanelPuntajeTotalTorneo = new javax.swing.JPanel();
        jLabelPuntajeTorneo = new javax.swing.JLabel();
        jLabelValorPuntajeTorneo = new javax.swing.JLabel();
        jScrollPaneTablaEquipo = new javax.swing.JScrollPane();
        jTableTablaEquipo = new javax.swing.JTable();
        jPanelPuntajeTotalFecha = new javax.swing.JPanel();
        jLabelPuntajeFecha = new javax.swing.JLabel();
        jLabelValorPuntajeFecha = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(tpdisenio2009.Tpdisenio2009App.class).getContext().getResourceMap(QueryPlayerScoresViewImpl.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setLocationByPlatform(true);
        setName("Form"); // NOI18N

        jComboBoxFecha.setToolTipText(resourceMap.getString("jComboBoxFecha.toolTipText")); // NOI18N
        jComboBoxFecha.setName("jComboBoxFecha"); // NOI18N

        jLabelCotizacion.setText(resourceMap.getString("jLabelCotizacion.text")); // NOI18N
        jLabelCotizacion.setName("jLabelCotizacion"); // NOI18N

        jLabelNombre.setFont(resourceMap.getFont("jLabelNombre.font")); // NOI18N
        jLabelNombre.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabelNombre.setText(resourceMap.getString("jLabelNombre.text")); // NOI18N
        jLabelNombre.setName("jLabelNombre"); // NOI18N

        jLabelFecha.setText(resourceMap.getString("jLabelFecha.text")); // NOI18N
        jLabelFecha.setName("jLabelFecha"); // NOI18N

        jLabelValorCotizacion.setFont(resourceMap.getFont("jLabelValorCotizacion.font")); // NOI18N
        jLabelValorCotizacion.setText(resourceMap.getString("jLabelValorCotizacion.text")); // NOI18N
        jLabelValorCotizacion.setName("jLabelValorCotizacion"); // NOI18N

        jButtonSalir.setText(resourceMap.getString("jButtonSalir.text")); // NOI18N
        jButtonSalir.setToolTipText(resourceMap.getString("jButtonSalir.toolTipText")); // NOI18N
        jButtonSalir.setName("jButtonSalir"); // NOI18N

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel1.border.title"))); // NOI18N
        jPanel1.setName("jPanel1"); // NOI18N

        jPanelPuntajeTotalTorneo.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanelPuntajeTotalTorneo.setName("jPanelPuntajeTotalTorneo"); // NOI18N

        jLabelPuntajeTorneo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabelPuntajeTorneo.setText(resourceMap.getString("jLabelPuntajeTorneo.text")); // NOI18N
        jLabelPuntajeTorneo.setName("jLabelPuntajeTorneo"); // NOI18N

        jLabelValorPuntajeTorneo.setFont(resourceMap.getFont("jLabelValorPuntajeTorneo.font")); // NOI18N
        jLabelValorPuntajeTorneo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabelValorPuntajeTorneo.setText(resourceMap.getString("jLabelValorPuntajeTorneo.text")); // NOI18N
        jLabelValorPuntajeTorneo.setName("jLabelValorPuntajeTorneo"); // NOI18N

        javax.swing.GroupLayout jPanelPuntajeTotalTorneoLayout = new javax.swing.GroupLayout(jPanelPuntajeTotalTorneo);
        jPanelPuntajeTotalTorneo.setLayout(jPanelPuntajeTotalTorneoLayout);
        jPanelPuntajeTotalTorneoLayout.setHorizontalGroup(
            jPanelPuntajeTotalTorneoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelPuntajeTotalTorneoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelPuntajeTotalTorneoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabelValorPuntajeTorneo)
                    .addComponent(jLabelPuntajeTorneo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanelPuntajeTotalTorneoLayout.setVerticalGroup(
            jPanelPuntajeTotalTorneoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelPuntajeTotalTorneoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelPuntajeTorneo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabelValorPuntajeTorneo)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jScrollPaneTablaEquipo.setName("jScrollPaneTablaEquipo"); // NOI18N

        jTableTablaEquipo.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"Arquero", null, null, null, null},
                {"Defensa 1", null, null, null, null},
                {"Defensa 2", null, null, null, null},
                {"Defensa 3", null, null, null, null},
                {"Defensa 4", null, null, null, null},
                {"Volante 1", null, null, null, null},
                {"Volante 2", null, null, null, null},
                {"Volante 3", null, null, null, null},
                {"Delantero 1", null, null, null, null},
                {"Delantero 2", null, null, null, null},
                {"Delantero 3", null, null, null, null},
                {"Arquero Sup.", null, null, null, null},
                {"Defensa Sup.", null, null, null, null},
                {"Volante Sup.", null, null, null, null},
                {"Delantero Sup.", null, null, null, null}
            },
            new String [] {
                "Posición", "Jugador", "Club", "Cotización", "Puntos"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTableTablaEquipo.setName("jTableTablaEquipo"); // NOI18N
        jTableTablaEquipo.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jTableTablaEquipo.getTableHeader().setReorderingAllowed(false);
        jScrollPaneTablaEquipo.setViewportView(jTableTablaEquipo);
        jTableTablaEquipo.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("jTableTablaEquipo.columnModel.title0")); // NOI18N
        jTableTablaEquipo.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("jTableTablaEquipo.columnModel.title1")); // NOI18N
        jTableTablaEquipo.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("jTableTablaEquipo.columnModel.title2")); // NOI18N
        jTableTablaEquipo.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("jTableTablaEquipo.columnModel.title3")); // NOI18N
        jTableTablaEquipo.getColumnModel().getColumn(4).setMinWidth(50);
        jTableTablaEquipo.getColumnModel().getColumn(4).setPreferredWidth(60);
        jTableTablaEquipo.getColumnModel().getColumn(4).setMaxWidth(70);
        jTableTablaEquipo.getColumnModel().getColumn(4).setHeaderValue(resourceMap.getString("jTableTablaEquipo.columnModel.title4")); // NOI18N

        jPanelPuntajeTotalFecha.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanelPuntajeTotalFecha.setAutoscrolls(true);
        jPanelPuntajeTotalFecha.setName("jPanelPuntajeTotalFecha"); // NOI18N

        jLabelPuntajeFecha.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabelPuntajeFecha.setText(resourceMap.getString("jLabelPuntajeFecha.text")); // NOI18N
        jLabelPuntajeFecha.setName("jLabelPuntajeFecha"); // NOI18N

        jLabelValorPuntajeFecha.setFont(resourceMap.getFont("jLabelValorPuntajeFecha.font")); // NOI18N
        jLabelValorPuntajeFecha.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabelValorPuntajeFecha.setText(resourceMap.getString("jLabelValorPuntajeFecha.text")); // NOI18N
        jLabelValorPuntajeFecha.setName("jLabelValorPuntajeFecha"); // NOI18N

        javax.swing.GroupLayout jPanelPuntajeTotalFechaLayout = new javax.swing.GroupLayout(jPanelPuntajeTotalFecha);
        jPanelPuntajeTotalFecha.setLayout(jPanelPuntajeTotalFechaLayout);
        jPanelPuntajeTotalFechaLayout.setHorizontalGroup(
            jPanelPuntajeTotalFechaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelPuntajeTotalFechaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelPuntajeTotalFechaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabelValorPuntajeFecha)
                    .addComponent(jLabelPuntajeFecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanelPuntajeTotalFechaLayout.setVerticalGroup(
            jPanelPuntajeTotalFechaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelPuntajeTotalFechaLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelPuntajeFecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabelValorPuntajeFecha)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPaneTablaEquipo, javax.swing.GroupLayout.DEFAULT_SIZE, 464, Short.MAX_VALUE)
                .addGap(10, 10, 10)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanelPuntajeTotalFecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanelPuntajeTotalTorneo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jPanelPuntajeTotalFecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanelPuntajeTotalTorneo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPaneTablaEquipo, javax.swing.GroupLayout.DEFAULT_SIZE, 268, Short.MAX_VALUE))
                .addGap(11, 11, 11))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabelNombre, javax.swing.GroupLayout.DEFAULT_SIZE, 362, Short.MAX_VALUE)
                        .addGap(22, 22, 22)
                        .addComponent(jLabelCotizacion)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabelValorCotizacion)
                        .addGap(18, 18, 18)
                        .addComponent(jLabelFecha)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jComboBoxFecha, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jButtonSalir, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelNombre)
                    .addComponent(jComboBoxFecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelFecha)
                    .addComponent(jLabelValorCotizacion)
                    .addComponent(jLabelCotizacion))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButtonSalir)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonSalir;
    private javax.swing.JComboBox jComboBoxFecha;
    private javax.swing.JLabel jLabelCotizacion;
    private javax.swing.JLabel jLabelFecha;
    private javax.swing.JLabel jLabelNombre;
    private javax.swing.JLabel jLabelPuntajeFecha;
    private javax.swing.JLabel jLabelPuntajeTorneo;
    private javax.swing.JLabel jLabelValorCotizacion;
    private javax.swing.JLabel jLabelValorPuntajeFecha;
    private javax.swing.JLabel jLabelValorPuntajeTorneo;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanelPuntajeTotalFecha;
    private javax.swing.JPanel jPanelPuntajeTotalTorneo;
    private javax.swing.JScrollPane jScrollPaneTablaEquipo;
    private javax.swing.JTable jTableTablaEquipo;
    // End of variables declaration//GEN-END:variables

    public void setFantasyTeamName(String fantasyTeamName) {
        jLabelNombre.setText( fantasyTeamName );
    }

    public void setCotization(Integer cotization) {
        jLabelValorCotizacion.setText( cotization.toString() );
    }

    public void setDates(List<TournamentDate> dates) {
        DefaultComboBoxModel model = new DefaultComboBoxModel();
        for (TournamentDate date : dates)
            model.addElement( date );
        jComboBoxFecha.setModel( model );
    }

    public TournamentDate getDate() {
        DefaultComboBoxModel model = (DefaultComboBoxModel) jComboBoxFecha.getModel();
        return (TournamentDate) model.getSelectedItem();
    }

    public void addDateChangeListener(ItemListener listener) {
        jComboBoxFecha.addItemListener( listener );
    }

    public void removeDateChangeListener(ItemListener listener) {
        jComboBoxFecha.removeItemListener( listener );
    }

    public void setDatePoints(Integer datePoints) {
        jLabelValorPuntajeFecha.setText( datePoints.toString() );
    }

    public void setTournamentPoints(Integer tournamentPoints) {
        jLabelValorPuntajeTorneo.setText( tournamentPoints.toString() );
    }

    public void loadFantasyTeam( Vector<Vector<String>> players ) {        
        DefaultTableModel model = (DefaultTableModel) jTableTablaEquipo.getModel();
        model.setNumRows( 0 );

        Vector<String> columName = new Vector<String>();
        columName.add( "Posición" );
        columName.add( "Jugador" );
        columName.add( "Club" );
        columName.add( "Cotización" );
        columName.add( "Puntos" );        

        model.setDataVector( players, columName );
        jTableTablaEquipo.setModel( model );
    }

    public void addExitListener(ActionListener listener) {
        jButtonSalir.addActionListener( listener );
    }

    public void removeExitListener(ActionListener listener) {
        jButtonSalir.removeActionListener( listener );
    }

    public void close() {
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        setVisible( false );
    }

    public Component asWidget() {
        return this;
    }
}
